package org.example.struct.array;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author liyishan
 * @date 2024/8/23 13:44
 * @apiNote
 */

public class Test00830LargeGroupPositions {
    public static void main(String[] args) {
        String s = "aaa";
        System.out.println(largeGroupPositions(s));
    }

    public static List<List<Integer>> largeGroupPositions(String s) {
        List<List<Integer>> res = new ArrayList<>();
        int num = 1;
        int n = s.length();
        for (int i = 0; i < n; i++) {
            if (i == n - 1 || s.charAt(i) != s.charAt(i + 1)) {
                if (num >= 3) {
                    res.add(Arrays.asList(i - num + 1, i));
                }
                num = 1;
            } else {
                num++;
            }
        }
        return res;
    }
}
